home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000088_icon-group-sender _Tue Oct 21 08:05:47 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id IAA18421
  4.     for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Tue, 21 Oct 1997 08:05:46 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA19492; Tue, 21 Oct 1997 08:05:46 -0700
  7. Posted-Date: Mon, 20 Oct 1997 22:09:15 -0500 (CDT)
  8. Date: Mon, 20 Oct 1997 22:09:15 -0500 (CDT)
  9. From: Chris Tenaglia <cdt@post.its.mcw.edu>
  10. To: gep2@computek.net
  11. Cc: icon-group@cs.arizona.edu
  12. Subject: Re: counting letters
  13. In-Reply-To: <199710201711.MAA10989@axp.cmpu.net>
  14. Message-Id: <Pine.SOL.3.96.971020220525.936A-100000@post.its.mcw.edu>
  15. Mime-Version: 1.0
  16. Content-Type: TEXT/PLAIN; charset=US-ASCII
  17. Errors-To: icon-group-errors@cs.arizona.edu
  18. Status: RO
  19.  
  20. Brute force procedural icon...
  21. ____________________________________________________
  22. procedure main()
  23.   count := table(0)
  24.   while line := read() do
  25.     every byte := !line do 
  26.       if any(&letters,byte) then 
  27.     count[byte] +:= 1
  28.   every byte := !&letters do 
  29.     (count[byte] = 0) | write(byte," ",count[byte])
  30.   end
  31. ____________________________________________________
  32. I'm sure there's briefer more collapsed
  33. method. This also ignores letters that
  34. don't occur, those with 0 occurrences.
  35.  
  36. Chris Tenaglia   (system manager)     |  The future foretold,
  37. Medical College of Wisconsin          |  The past explained,
  38. 8701 W. Watertown Plank Rd.           |  The present largely appologized for.
  39. Milwaukee, WI 53226   (414)456-8765   |  Organon to the Doctor
  40.  
  41.  
  42. On Mon, 20 Oct 1997 gep2@computek.net wrote:
  43.  
  44. > Date: Mon, 20 Oct 1997 12:11:29 -0500
  45. > From: gep2@computek.net
  46. > To: icon-group@cs.arizona.edu
  47. > Subject: counting letters
  48. > >What would be the best way to design an Icon program that takes a text
  49. > file as input, counts up the instances of every letter in the alphabet
  50. > (ignoring other characters and distinguishing between uppercase and
  51. > lowercase letters), and spits out the results of the count as output?
  52. > Define "best"... smallest, simplest, fastest, most elegant?
  53. > >For example, the following input
  54. > abcdefghjijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()
  55. > would produce the following output
  56. > >a  1
  57. > b  2
  58. > [etc.]
  59. > A  1
  60. > b  2
  61. > [etc.]
  62. > [nothing for the non-alphabetic characters]
  63. > In SNOBOL4+/SPITBOL, one program would be:
  64. > -PLUSOPS 1
  65. >           T = TABLE()
  66. >           CHRSET = &LCASE &UCASE
  67. > GETREC    LINE = INPUT                  :F(EOF)
  68. > COUNT     LINE BREAK(CHRSET) ANY(CHRSET) . LET = ?(T[LET] = T[LET] + 1) 
  69. > +                                                        :S(COUNT)F(GETREC)
  70. > EOF       A = SORT(TABLE,1)             :F(DONE)
  71. > LIST      OUTPUT = A[(N = N + 1),1] "  " A[N,2]          :S(LIST)
  72. > END
  73. > Gordon Peterson
  74. > http://www.computek.net/public/gep2/
  75. > Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  76.  
  77.